package org.zachary.prosocialbehaviorservice.interfaces;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import org.zachary.prosocialbehaviorservice.application.ActivityItemService;
import org.zachary.prosocialbehaviorservice.application.ActivityQueryService;
import org.zachary.prosocialbehaviorservice.application.command.ActivityItemAddCommand;
import org.zachary.prosocialbehaviorservice.application.command.ModifyActivityItemCommand;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.ActivityItemWithCategoryDTO;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.ActivityItem;
import org.zachary.prosocialbehaviorservice.infrastructure.utils.Result;

import java.util.List;

@Api(tags = "亲社会行为模块——活动项目细则")
@RestController
@RequestMapping("/activity/item")
public class ActivityItemController {
    private final ActivityItemService activityItemService;
    private final ActivityQueryService activityQueryService;

    public ActivityItemController(ActivityItemService activityItemService, ActivityQueryService activityQueryService) {

        this.activityItemService = activityItemService;
        this.activityQueryService = activityQueryService;
    }

    @PostMapping("/add")
    public Result<String> addItem(@RequestParam("activityId")Integer activityId,@RequestBody ActivityItemAddCommand command){
        System.out.println(command);
        activityItemService.addActivityItem(activityId,command);
        return Result.success("添加成功");
    }

    @DeleteMapping("/delete")
    public Result<String> deleteItem(@RequestParam Integer itemId){
        activityItemService.delete(itemId);
        return Result.success("删除成功");
    }
    @PostMapping("/modify")
    public Result<String> findItem(@RequestParam("activityId")Integer activityId,@RequestBody ModifyActivityItemCommand command){
        activityItemService.modify(activityId,command);
        return Result.success("修改成功");
    }

    @GetMapping("/list")
    public Result<List<ActivityItemWithCategoryDTO>> findAll(){
        List<ActivityItemWithCategoryDTO> list=activityQueryService.findAllWithCategory();
        return Result.success(list);
    }

    @GetMapping("/detail")
    public Result<ActivityItem> findItem(@RequestParam Integer itemId){
        ActivityItem item=activityItemService.findById(itemId);
        if(item==null){
            return Result.fail("查询结果为空");
        }
        return Result.success(item);
    }
}
